import requests
from lxml import etree
url = "https://movie.douban.com/top250"
headers = {
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
}
params = {
    'start':0
}
'''
//ol[@class="grid_view"]//span[@class="title"][1]/text()  ->取名称
//ol[@class="grid_view"]//div[@class="bd"]/div/span[2]/text() -->取分数
//ol[@class="grid_view"]//div[@class="bd"]/div/span[4]/text() -->取多少人评分
'''
names = []
rates = []
persons = []

for i in range(0,250,25):
    params["start"] = i
    resp = requests.get(url,headers=headers,params=params)
    if resp.status_code==200:
        en = etree.HTML(resp.text)
        tnames = en.xpath('//ol[@class="grid_view"]//span[@class="title"][1]/text()')
        trates = en.xpath('//ol[@class="grid_view"]//div[@class="bd"]/div/span[2]/text()')
        names[-1::] = tnames
        rates[-1::] = trates
        persons[-1::] = en.xpath('//ol[@class="grid_view"]//div[@class="bd"]/div/span[4]/text()')

for n,r,p in zip(names,rates,persons):
    print(f"{n}--->{r}--->{p}")